package com.baiyang.server.service.system.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baiyang.server.dao.system.RouteDao;
import com.baiyang.server.dao.system.RouteRoleDao;
import com.baiyang.server.model.system.Route;
import com.baiyang.server.service.impl.BaseServiceImpl;
import com.baiyang.server.service.system.RouteService;
import com.baiyang.server.tools.Data;
import com.baiyang.server.tools.DataTool;

/**
 * 
 * @author XVX
 * BY: @Primary 注解帮助生命@Autowired优先注入的实列
 */
@Service	
public class RouteServiceImpl extends BaseServiceImpl<RouteDao, Route>implements RouteService{
	@Autowired
	private RouteDao routeDao = null;
	@Autowired
	private RouteRoleDao routeRoleDao = null;
	
	@Override
	public List<Route> getRoutes(List<String> roleIds) {
		if(DataTool.isBlank(roleIds)) {
			return null;
		}
		//判断是否拥有管理员角色
		boolean flag = false;
		for (String roleId : roleIds) {
			if(Data.DataDictionary.SUPER_ADMIN_ROLE_ID.equals(roleId)) {
				flag = true;
			}
		}
		List<Route> routes = null;
		if(flag) {
			//获取所有路由信息
			Route route = new Route();
			route.setDel("0");
			route.setAvailable("1");
			routes = routeDao.selectList(route);
		}else {
			//根据角色获取路由信息
			routes = routeDao.selectByRoleIds(roleIds);
		}
		return routes;
	}
	
	
}
